/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package games.freecell.control;

import commomgame.Director;
import commomgame.Region;
import commomgame.SubRegion;
import games.freecell.structure.RegionOfCells;
import games.freecell.structure.RegionOfReservesFreeCell;
import games.patience.core.RegionOfFoundations;

/**
 *
 * @author João Carlos Nunes Bittencourt
 */
public class FreeCellDirector extends Director {

    public static boolean invokeRuleReserveReserve(int value, String nipe, String origin, String target, RegionOfReservesFreeCell regionOrigin, RegionOfReservesFreeCell regionTarget, RegionOfCells Cells) {

        return regionTarget.verifyRuleRegionToRegion(value, nipe, Director.searchSubRegionOfReserves(origin, regionOrigin), searchSubRegionOfReserves(target, regionTarget), Cells);

    }
    
    public static boolean invokeRuleReserveCells(int value, String nipe, String origin, String target, RegionOfReservesFreeCell regionOrigin, RegionOfCells regionTarget) {

        return regionTarget.verifyRule(value, nipe, Director.searchSubRegionOfReserves(origin, regionOrigin), searchSubRegionOfCells(target, regionTarget));

    }

    public static boolean invokeRuleCellsFoundations(int value, String nipe, String origin, String target, RegionOfCells regionOrigin, RegionOfFoundations regionTarget) {

        return regionTarget.verifyRule(value, nipe, searchSubRegionOfCells(origin, regionOrigin), Director.searchSubRegionOfFoundations(target, regionTarget));

    }

    public static boolean invokeRuleCellsReserve(int value, String nipe, String origin, String target, RegionOfCells regionOrigin, RegionOfReservesFreeCell regionTarget) {

        return regionTarget.verifyRule(value, nipe, searchSubRegionOfCells(origin, regionOrigin), Director.searchSubRegionOfReserves(target, regionTarget));

    }

    public static SubRegion searchSubRegionOfCells(String name, RegionOfCells region) {
        for (int i = 0; i < region.getNumberOfSubRegions(); i++) {
            if (region.getRegion().get(i).getName().equals(name)) {
                return region.getRegion().get(i);
            }
        }

        return null;
    }

    /*public static SubRegion searchSubRegionOfReserves(String name, RegionOfReservesFreeCell region) {
        for (int i = 0; i < region.getNumberOfSubRegions(); i++) {
            if (region.getRegion().get(i).getName().equals(name)) {
                return region.getRegion().get(i);
            }
        }

        return null;
    }*/
}
